@extends('layouts.tankuang')

@section('content')
    <!--startprint-->
    <form name="add_form" id="add_form" method="post" action="{{url('admin/units/edit',$id)}}" enctype="multipart/form-data" style="overflow:hidden;height:100%;">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div id="div_print">
            <h2 class="text-center mg_b36 w mg_t25" style="font-weight: bold;">企事业单位基本情况登记表</h2>
            <table class="table-form table-border w mg-auto">
                <tbody>
                    {{--@if($re->pic != '')
                        <tr>
                            <td class="font-bd" align="center" width="10%">单位图片</td>
                            <td colspan="5"><div class="example  col-md-12 col-xs-12 "><img src="{{ URL::asset('/') }}{{$re->pic}}" class="img-rounded" alt="" width="50"></div></td>
                        </tr>
                    @endif--}}

                    <tr>
                        <td class="font-bd" align="center" width="16%">单位名称</td>
                        <td colspan="2"><input type="text" class="form-input w easyui-validatebox" value="{{$re->name}}" name="name" data-options="required:true,missingMessage:'单位名称不能为空',validateOnCreate:false,validateOnBlur:true"></td>
                        <td rowspan="4" style="width: 190px;text-align: center;">
                            @if($re->pic != '')
                                <div class="example" style="width: 190px;display: inline-block;"><img src="{{ URL::asset('/') }}{{$re->pic}}" class="img-rounded" alt="" style="width: 190px;border-radius: 0;"></div>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">详细地址</td>
                        <td colspan="2"><input type="text" class="form-input w easyui-validatebox"  value="{{$re->address}}" name="address" data-options="required:true,missingMessage:'详细地址不能为空',validateOnCreate:false,validateOnBlur:true"></td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">原辖区派出所</td>
                        <td colspan="2"><input type="text" class="form-input w" value="{{getValue($re->city,'area','id','name')}}{{getValue($re->area,'area','id','name')}}{{getValue($re->org_id,'area','id','name')}}" disabled></td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">新辖区派出所</td>
                        <td colspan="2">
                            <div class="col-sm-3" style="margin-left: -15px;">
                                <select id="city" name="city" class="w150 input_all " style="width: 120px;">
                                    <option value="">请选择</option>
                                    @foreach($city as $v)
                                        <option value="{{$v->id}}">{{$v->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-sm-3" style="margin-left:15px;">
                                <select id="area" name="area" class="w150 input_all" style="width: 120px;">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                            <div class="col-sm-3" style="margin-left:15px;">
                                <select id="org_id" name="org_id" class="w150 input_all" style="width: 120px;">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </td>
                    </tr>
                    <tr><td colspan="4" style="background-color: #69CEE9;text-align: center">单位信息</td></tr>
                    <tr>
                        <td class="font-bd" align="center" width="16%">统一社会信用码</td>
                        <td width="34%">
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->zuzhijigou}}" name="zuzhijigou" data-options="required:true,missingMessage:'统一社会信用码不能为空',validateOnCreate:false,validateOnBlur:true">（18位）
                        </td>
                        <td class="font-bd" align="center" width="16%">所属行业类别</td>
                        <td width="34%">
                            <select class="w153 input_all easyui-validatebox" name="type" data-options="required:true,missingMessage:'行业类别不能为空',validateOnCreate:false,validateOnBlur:true">
                                <option value="">请选择行业类别</option>
                                @foreach($type as $k=>$v)
                                    <option value="{{$v->id}}" @if($re->type == $v->id) selected @endif>{{$v->name}}</option>
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">重点级别</td>
                        <td>
                            <select class="w153 input_all easyui-validatebox" name="is_imp" data-options="required:true,missingMessage:'重点级别不能为空',validateOnCreate:false,validateOnBlur:true">
                                <option value="">请选择重点级别</option>
                                <option value="10" @if($re->is_imp == 10) selected @endif>省级重点单位</option>
                                <option value="20" @if($re->is_imp == 20) selected @endif>市级重点单位</option>
                                <option value="30" @if($re->is_imp == 30) selected @endif>县区级重点单位</option>
                                <option value="40" @if($re->is_imp == 40) selected @endif>一般单位</option>
                            </select>
                        </td>
                        <td class="font-bd" align="center">单位性质</td>
                        <td>
                            <select id="area" name="xingzhi" class="w150 input_all easyui-validatebox" style="width: 120px;" data-options="required:true,missingMessage:'单位性质不能为空',validateOnCreate:false,validateOnBlur:true">
                                <option value="">请选择单位性质</option>
                                <option value="10" @if($re->xingzhi == '10')selected @endif>国有</option>
                                <option value="20" @if($re->xingzhi == '20')selected @endif>民营</option>
                                <option value="30" @if($re->xingzhi == '30')selected @endif>股份</option>
                                <option value="40" @if($re->xingzhi == '40')selected @endif>合资</option>
                                <option value="50" @if($re->xingzhi == '50')selected @endif>外资</option>
                                <option value="60" @if($re->xingzhi == '60')selected @endif>个体</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">上级部门</td>
                        <td>
                            <input type="text" class="form-input" name="shangjibumen" value="{{$re->shangjibumen}}">
                        </td>
                        <td class="font-bd" align="center">单位状态</td>
                        <td>
                            <select class="w153 input_all" name="is_del">
                                <option value="0" @if($re->is_del == 0) selected @endif>实有</option>
                                <option value="1" @if($re->is_del == 1) selected @endif>注销</option>
                                <option value="2" @if($re->is_del == 2) selected @endif>合并</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">固定资产（万元）</td>
                        <td>
                            <input type="text" class="form-input" value="{{$re->gdzc}}" name="gdzc">
                        </td>
                        <td class="font-bd" align="center">要害部门部位数量</td>
                        <td>
                            <input type="text" class="form-input" value="{{$count['buwei_num']}}" disabled>
                        </td>
                    </tr>
                    <tr><td colspan="4" style="background-color: #69CEE9;text-align: center">人员信息</td></tr>
                    <tr>
                        <td class="font-bd" align="center">在职职工总数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$re->zaizhi_num_of_peo}}" name="zaizhi_num_of_peo">
                        </td>
                        <td class="font-bd" align="center">在职保安人数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$count['zaizhi_num']}}" disabled>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">自招保安人数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$count['zizhao_num']}}" disabled>
                        </td>
                        <td class="font-bd" align="center">外聘保安人数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$count['waipin_num']}}" disabled>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">重点岗位人数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$count['zdgw_num']}}" disabled>
                        </td>
                        <td class="font-bd" align="center">维稳对象人数</td>
                        <td>
                            <input type="text" class="form-input" value="{{$re->zdwwgzdx_num_of_peo}}" name="zdwwgzdx_num_of_peo">
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">单位法人</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->frdb_name}}" name="frdb_name" data-options="required:true,missingMessage:'单位法人不能为空',validateOnCreate:false,validateOnBlur:true">
                        </td>
                        <td class="font-bd" align="center">联系电话</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->frdb_phone}}" name="frdb_phone" data-options="required:true,validType:'phoneAndMobile',missingMessage:'联系电话不能为空',invalidMessage:'请输入正确的联系电话',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">保卫负责人</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->bwfzr_name}}" name="bwfzr_name" data-options="required:true,missingMessage:'保卫负责人不能为空',validateOnCreate:false,validateOnBlur:true">
                        </td>
                        <td class="font-bd" align="center">联系电话</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->bwfzr_phone}}" name="bwfzr_phone" data-options="required:true,validType:'phoneAndMobile',missingMessage:'联系电话不能为空',invalidMessage:'请输入正确的联系电话',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd" align="center">责任民警</td>
                        <td>
                            <select class="w153 input_all easyui-validatebox" name="minjing" data-options="required:true,missingMessage:'责任民警不能为空',validateOnCreate:false,validateOnBlur:true">
                                <option value="">请选择</option>
                                @foreach($police as $k=>$v)
                                    <option value="{{$v->id}}" @if($re->minjing == $v->id) selected @endif>{{$v->name}}</option>
                                @endforeach
                            </select>
                        </td>
                        <td class="font-bd" align="center">联系电话</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" value="{{$re->minjing_phone}}" name="minjing_phone" data-options="required:true,validType:'phoneAndMobile',missingMessage:'联系电话不能为空',invalidMessage:'请输入正确的联系电话',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>
                    <tr><td colspan="4" style="background-color: #69CEE9;text-align: center">GIS信息</td></tr>
                    <tr>
                        <td class="font-bd" align="center">经度</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" name="jd" value="{{$re->jd}}" data-options="required:true,missingMessage:'经度不能为空',validateOnCreate:false,validateOnBlur:true">
                        </td>
                        <td class="font-bd" align="center">纬度</td>
                        <td>
                            <input type="text" class="form-input easyui-validatebox" name="wd" value="{{$re->wd}}" data-options="required:true,missingMessage:'纬度不能为空',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>
                    <tr><td colspan="4" style="background-color: #69CEE9;text-align: center">行业信息</td></tr>
                    @foreach($field as $vv)
                        <tr>
                            @foreach($vv as $v)
                                <td class="font-bd" align="center">{{$v->field_content}}</td>
                                <td>
                                    @if($v->field_type == 1)
                                        <input type="text" class="form-input" value="{{getFieldValue($re->id,$re->type,$v->id)}}" name="field[{{$v->field_name}}]">
                                    @elseif($v->field_type == 2)
                                        <select class="w153 input_all" name="field[{{$v->field_name}}]">
                                            <option value="">请选择</option>
                                            @foreach($v->daan as $v2)
                                                <option value="{{$v2->val}}" @if(getFieldValue($re->id,$re->type,$v->id) == $v2->val) selected @endif>{{$v2->val}}</option>
                                            @endforeach
                                        </select>
                                    @endif
                                </td>
                            @endforeach
                        </tr>
                    @endforeach
                    <tr>
                        <td class="font-bd" align="center">备注</td>
                        <td colspan="3">
                            <textarea class="textarea" name="remark">{{$re->remark}}</textarea>
                        </td>
                    </tr>
                </tbody>
            </table>
            <!--endprint-->
            <div class="w wbt mg_t25 pd_b60 text-center">
                <button id="go" type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-save'">确定</button>
                <a id="goToPageB" class="easyui-linkbutton dsp print" data-options="iconCls:'icon-print'" onclick="getjwd()">点击获取经纬度</a>
                <a href="{{url('admin/units/print_unit',$id)}}" target="_blank" id="goToPageB" class="easyui-linkbutton dsp print" data-options="iconCls:'icon-print'">打印</a>
                <div class="box_bt">
                	<span class="img_add"><img src="{{ URL::asset('/') }}/css/icons/pencil.png">修改单位图片</span>
                  	 <input class="box_file" type="file" name="pic">
                </div>
                <!--<button type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-no'" onclick="$('#w').window('close')">关闭</button>-->
            </div>
        </div>
    </form>

    <div id="jwd" class="easyui-window" closed="true" title="新增" data-options="iconCls:'icon-save'" style="width:700px;height:500px;padding:10px;">

    

    <link rel="stylesheet" href="{{ URL::asset('/') }}css/zoomify.min.css">
    <script src="{{ URL::asset('/') }}js/zoomify.min.js"></script>
    <script type="text/javascript">
        $('.example img').zoomify(function(){
            $(this).css({'position':'absolute','top':0,'bottom':0,'left':0,'right':0,'z-index':'9999',})
        });
    </script>
        <script type="text/javascript">
            $(document).on("change",'#city', function(){

                $('#area option:gt(0)').remove();
                $('#org_id option:gt(0)').remove();
                //alert(1);die;
                var cid = $("#city").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#area").append(option);
                        });
                    }
                });
            });

            $(document).on("change",'#area', function(){
                $('#org_id option:gt(0)').remove();
                var cid = $("#area").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#org_id").append(option);
                        });
                    }
                });
            });
        </script>
    <script>
        $('#go').click(function (){
        	if(!$("#add_form").form('validate')){
				return false;
				}
            var formData = new FormData($("#add_form")[0]);
            $.ajax({
                type: "POST",
                url: "{{url('admin/units/edit',$id)}}",
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    if(data.status == 1){
                        $.messager.alert('信息提示',data.msg,'info');
                        $('#w').dialog('close');
                        $('.pagination-load').click();
                    }else{
                        $.messager.alert('信息提示',data.msg,'info');
                    }
                },
                error: function(msg) {
                    var json=JSON.parse(msg.responseText);
                    $.each(json, function(index, value) {
                        $.messager.alert('信息提示',value,'info');die;
                    });
                },
            });
        });
    </script>
    <script type="text/javascript">
        function doPrint() {
            /*bdhtml=window.document.body.innerHTML;
            sprnstr="<!--startprint-->";
            eprnstr="<!--endprint-->";
            prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
            prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
            window.document.body.innerHTML=prnhtml;
            window.print();*/

            winname = window.open('', "_blank",'');
            bdhtml=window.document.body.innerHTML;
            sprnstr="<!--startprint-->";
            eprnstr="<!--endprint-->";
            prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
            prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
            winname.document.body.innerHTML=prnhtml;
            winname.print();
        }
    </script>

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=hrVnXxLAGVr6QZ0rt9MaxU8bBkwKzyQC"></script>
    <script type="text/javascript">
        function getjwd(){
            $('#jwd').window({
                title: "获取经纬度",
                href: '/admin/units/getjwd',
                width:'700',
                height:'500',
                minimizable:false,
                top:500,
                left:($(window).width() - 700) * 0.5,
                modal:true,
                closed: false,
            });
        }
    </script>
@stop